package com.qmai.util.dto;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 功能：批次提交的信息
 *
 * @author chuchengyi
 */
public class BatchResult<T> {

    /**
     * 功能：是否成功
     */
    private boolean status;

    /**
     * 功能：错误编码
     */
    private long code;

	/**
	 * 功能：错误消息
	 */
	private String message;

    /**
     * 功能：成功的数据对象
     */
    private List<T> successData = new ArrayList<>();


    /**
     * 功能：失败的数据对象
     */
    private List<T> failData = new ArrayList<>();


    /**
     * 功能：失败的信息
     */
    private Map<T, ExceptionInfo> exceptionMap = new HashMap<>();


	public boolean isStatus() {
		return status;
	}

	public void setStatus(boolean status) {
		this.status = status;
	}

	public long getCode() {
		return code;
	}

	public void setCode(long code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public List<T> getSuccessData() {
		return successData;
	}

	public void setSuccessData(List<T> successData) {
		this.successData = successData;
	}

	public List<T> getFailData() {
		return failData;
	}

	public void setFailData(List<T> failData) {
		this.failData = failData;
	}

	public Map<T, ExceptionInfo> getExceptionMap() {
		return exceptionMap;
	}

	public void setExceptionMap(Map<T, ExceptionInfo> exceptionMap) {
		this.exceptionMap = exceptionMap;
	}

	/**
     * 功能：添加成功的数据信息
     *
     * @param model
     */
    public void addSuccess(T model) {
        this.successData.add(model);
    }

    /**
     * 功能：返回失败的数据对象
     *
     * @param model
     */
    public void addFail(T model) {
        this.failData.add(model);
    }


    /**
     * 功能：直接定义异常
     *
     * @param info
     */
    public void setException(ExceptionInfo info) {
        this.code = info.getErrorCode();
        this.message = info.getErrorMessage();
    }

    /**
     * 功能：设置异常信息
     *
     * @return
     */
    public ExceptionInfo exceptionInfo() {
        return new ExceptionInfo(this.getCode(), this.getMessage());
    }

    /**
     * 功能：添加异常信息
     *
     * @param model
     */
    public void addException(T model,ExceptionInfo exception) {
        this.exceptionMap.put(model, exception);
    }

	@Override
	public String toString() {
		return "BatchResult{" +
				"status=" + status +
				", code=" + code +
				", message='" + message + '\'' +
				", successData=" + successData +
				", failData=" + failData +
				", exceptionMap=" + exceptionMap +
				'}';
	}
}
